package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.CaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * @author: hippo
 */
@RestController
public class CaseController {

    @Autowired
    private CaseService caseService;

    @RequiresPermissions("case:list")
    @PostMapping("/getCaseList")
    public JSONObject getCaseList(@RequestBody JSONObject obj) {
        return caseService.getCaseList(obj);
    }

    @RequiresPermissions("case:add")
    @PostMapping("/addCase")
    public JSONObject addCase(@RequestBody JSONObject obj) {
        return caseService.addCase(obj);
    }

    @RequiresPermissions("case:update")
    @PutMapping("/updateCase")
    public JSONObject updateCase(@RequestBody JSONObject obj) {
        return caseService.updateCase(obj);
    }

    @RequiresPermissions("case:delete")
    @DeleteMapping("/deleteCase/{id}")
    public JSONObject addCase(@PathVariable String id) {
        return caseService.deleteCase(id);
    }

    @RequiresPermissions("case:run")
    @PostMapping("/runCase")
    public JSONObject runCase(@RequestBody JSONObject obj) {
        return caseService.runCase(obj);
    }

    @GetMapping("/getOperationList")
    public JSONObject getOperationList() {
        return caseService.getOperationList();
    }

    @GetMapping("/getCaseInfoById/{id}")
    public JSONObject getCaseInfoById(@PathVariable String id) {
        return caseService.getCaseInfoById(id);
    }

    @PostMapping(value = "/downloadTemplate")
    public void downloadTemplate(@RequestBody JSONObject obj, HttpServletResponse response) throws Exception {
        caseService.downloadTemplate(obj, response);
    }
}
